<?php
define('DB_NAME', $GLOBALS['dance_run']['db_name']);

function connDB()
{
	$conn = new Sqlite();
	$conn->connection(DB_NAME);
	return $conn;
}

function queryData($table, $filter)
{
	$conn = connDB();
	$conn->sql = "SELECT * FROM `$table` WHERE 1=1" . $filter;
	return $conn;
}

function getRows($table, $filter = '')
{
	$res = [];
	$conn = queryData($table, $filter);
	$res = $conn->rows();
	return $res;
}

function getRow($table, $filter = '')
{
	$res = [];
	$conn = queryData($table, $filter);
	$res = $conn->row();
	return $res;
}

function getCount($table, $filter = '')
{
	$res = 0;
	$conn = queryData($table, $filter);
	$res = $conn->count();
	return $res;
}

function interceptString($string, $length, $ellipsis = '...')
{
	$result = $string;
	if (mb_strlen($string) > $length) {
		$result = substr($string, 0, $length) . $ellipsis;
	}
	return $result;
}
?>